package com.cxk.hr.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cxk.hr.pojo.Employee;
import com.cxk.hr.pojo.Leave;
import com.cxk.hr.service.EmployeeService;
import com.cxk.hr.service.LeaveService;
import com.cxk.hr.service.impl.EmployeeServiceImpl;
import com.cxk.hr.service.impl.LeaveServiceImpl;

@Controller
@RequestMapping("leave")
public class LeaveContorller {
	@Autowired
	EmployeeService employeeService = new EmployeeServiceImpl();
	@Autowired
	private LeaveService leave = new LeaveServiceImpl();

	@RequestMapping("/oneself/{id}/addleave") // 申请请假
	public String addleave(Model model, @PathVariable Integer id) {
		Employee employee = (Employee) employeeService.findEmpById(id);
		model.addAttribute("employee", employee);
		return "leave_add";
	}

	@RequestMapping("/oneself/{id}/selflea") // 查看自己的请假
	public String selflea(@PathVariable Integer id, Model model) {
		Employee employee = (Employee) employeeService.findEmpById(id);
		List<Leave> leave = employeeService.findAlllea(employee.getId());
		model.addAttribute("leave", leave);
		return "oneself_leave";
	}

	//
	//

	@RequestMapping("tonolist")
	public String tonolist(Model model) {
		List<Leave> allLeas = leave.findAllLea(null, "未批准");
		// System.out.println("................"+allLeas);
		model.addAttribute("allLeas", allLeas);
		return "leave_notlist";
	}

	@RequestMapping("examine")
	public String examine(String employeeNum, Model model) {
		List<Leave> Leave = leave.findAllLea(Integer.parseInt(employeeNum), "未批准");
		System.out.println("..........." + Leave);
		model.addAttribute("Leave", Leave);
		return "leave_detail";
	}

	@RequestMapping("updatestatus")
	public String updateStatus(String empNum) {
		leave.updateStatus(Integer.parseInt(empNum));
		return "forward:tonolist";

	}

	@RequestMapping("toyeslist")
	public String toyesList(Model model) {
		List<Leave> allLeas = leave.findAllLea(null, "已批准");
		// System.out.println("................"+allLeas);
		model.addAttribute("allLeas", allLeas);
		return "leave_yeslist";
	}

	@RequestMapping("tolist")
	public String toList(Model model) {
		List<Leave> allLeas = leave.findAllLea(null, null);
		model.addAttribute("allLeas", allLeas);
		return "leave_list";

	}
}
